/**
 * SimpleKeywordFilter.java
 * @author Daniel Liu
 * Create: 2007-1-3 ����12:59:31
 */
package org.lex.ftp.ui.find.old.speed;

import java.util.Arrays;

import org.lex.filter.Filter;
import org.lex.net.ftp.FTPFile;
import org.lex.utils.text.Splitter;


public class FileEntryNameFilter implements Filter {
	private static final String[] EMPTY_ARRAY = new String[0];

	private String[] keywords = EMPTY_ARRAY;

	public FileEntryNameFilter() {
		this("");
	}

	public FileEntryNameFilter(String keyword) {
		super();
		this.setKeywords(keyword);
	}

	public void setKeywords(String keyword) {
		if (null == keyword)
			return;
		keywords = Splitter.BlankSpaceSplitter.split(keyword.toLowerCase());
	}

	public boolean accept(Object o) {
		if (null == o || false == o instanceof FTPFile)
			return false;
		String str = ((FTPFile) o).getName().toLowerCase();
		long strLen = str.length();
		for (String key : keywords)
			if (strLen >= key.length() && true == str.contains(key))
				return true;
		return false;
	}

	@Override
	public String toString() {
		return Arrays.toString(this.keywords);
	}
}
